package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    @PostMapping
    public R addCategory(@RequestBody Category category){
        R r = categoryService.addCategory(category);
        return r;
    }


    @GetMapping("/page")
    public R page(Integer page,Integer pageSize){
        R r = categoryService.page(page,pageSize);
        return r;
    }


    @DeleteMapping()
    public R removeCategoryById(Long id){
        R r = categoryService.removeCategoryById(id);
        return r;
    }

    @PutMapping
    public R modifyCategoryById(@RequestBody Category category){
        R r = categoryService.modifyCategoryById(category);
        return r;
    }

    @GetMapping("/list")
    public R findListByType(Integer type){
        R r = categoryService.findListByType(type);
        return r;
    }

}
